#pragma comment(linker, "/STACK:10000000")
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
#include <string>
#include <cstring>
#define ldb long double
#define LL long long
#define fi first
#define se second
#define fill(a, c) memset(a, c, sizeof(a))
#define sqr(a) ((a) * (a))
#define nextLine() {int c = 0; while((c = getchar()) != 10 && c != EOF);}
#define getBit(mask, k) (((mask) / pw[k]) % pw[1])
#define setBit(mask, k, l) (((mask) / pw[k + 1] * pw[1] + (l)) * pw[k] + ((mask) % pw[k]))
#define debug(a) cerr << #a << " = " << a << " ";
#define debugl(a) cerr << #a << " = " << a << "\n";
const ldb LDINF = 9128739847123.00;
const ldb eps = 1e-9;
const int INF = 1 << 30;
const ldb pi = fabsl(atan2(0.0, -1.0));
using namespace std;
char s[100500];
string t;
int n;

void Load()
{
	gets(s);
	n = strlen(s);
}

bool query(int k)
{
	bool can = true;
	for (int i = 0; can && i < k; i++)
	{
		t[i] = s[i];
	    if (s[i] == '4') continue;
	    if (s[i] == '7') continue;
	    can = false;
	}
	if (!can) return false;
	bool more = 0;
	for (int i = k; i < n; i++)
	{
		if (more == 0 && s[i] < '4')
		{
			t[i] = '4';
			more = 1;
		}
		else if (more == 0 && s[i] < '7')
		{
			t[i] = '7';
			more = 1;
		}
		else if (more == 0)
			return false;
		else if (more == 1)
			t[i] = '4';
	}
	return true;
}

void getMore()
{
	int i;
	for (i = 0; i < n && (s[i] == '4' || s[i] == '7'); t += s[i], i++);
	if (i == n) return;
	if (s[i] < '4')
		for (; i < n; i++)
			t += '4';
	else if (s[i] < '7')
	{
		t += '7';
		i++;
		for (; i < n; i++)
			t += '4';
	}
	else 
	{
		int j;
		for (j = i - 1; j >= 0 && s[j] == '7'; j--);
		if (j == -1)
		{
			t = string(n + 1, '4');
			return;
		}
		t = t.substr(0, j);
		t += '7';
		t += string(n - j - 1, '4');
	}
}

void do47(int cnt4, int cnt7)
{
	for (int i = t.size() - 1; cnt4 > cnt7 && i >= 0; i--)
	{
		if (t[i] == '4')
		{
			cnt4--;
			cnt7++;
			t[i] = '7';
		}
	}
	printf("%s", t.c_str());
}

void Solve()
{
	getMore();
	if (t.size() % 2 == 1)
	{
		printf("%s", string((t.size() + 1) / 2, '4').c_str());
		printf("%s", string((t.size() + 1) / 2, '7').c_str());
		return;
	}
	int cnt4 = 0, cnt7 = 0;
	for (int i = 0; i < t.size(); i++)
	{
		if (t[i] == '4') cnt4++;
		if (t[i] == '7') cnt7++;
	}                           
	if (cnt4 == cnt7)
	{
		printf("%s", t.c_str());
		return;
	}
	if (cnt4 > cnt7)
	{
		do47(cnt4, cnt7);
		return;	
	}
	int v = 0, f = 0;
	for (int i = t.size() - 1; i >= 0; i--)
	{
		if (t[i] == '4') f++;
		else v++;
		if (t[i] == '4')
		{
			if (cnt7 - v + 1 <= cnt4 - f + t.size() - i - 1)
			{
				t[i] = '7';
				do47(cnt4 - f + t.size() - i - 1, cnt7 - v + 1);
				return;
			}
		}
		t[i] = '4';
	}
	printf("%s", string((t.size() + 2) / 2, '4').c_str());
	printf("%s", string((t.size() + 2) / 2, '7').c_str());

}

#define file "b"
int main()
{
	#ifndef ONLINE_JUDGE
		freopen(file".in", "rt", stdin);
		freopen(file".out", "wt", stdout);
	#endif
	Load();
	Solve();
	return 0;
}
